<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<script src="../../js/lib/jquery-v3.0.0/jquery.js" type="text/javascript" charset="utf-8"></script>
		<title>jQuery.proxy</title>
	</head>

	<body>
		<p>jquery proxy</p>
		<div id="test" style="border: 2px groove dodgerblue; width: 100px;">Click Here!</div>
		<script type="text/javascript">
			var obj = {
				name: "John",
				test: function(event) {
					debugger;
					//this指向obj，click触发的方法为test
					alert(this.name);
					$("#test").unbind("click", obj.test);
				}
			};
//			$("#test").click(function (event) {
//				//this指向id为test的dom对象
//				debugger;
//			});
			//设置作用域为obj，触发的方法为obj.test
//			$("#test").click(jQuery.proxy(obj, "test"));

			// 以下代码跟上面那句是等价的:
			 //$("#test").click( jQuery.proxy( obj.test, obj ) );

			// 可以与单独执行下面这句做个比较。
//			 $("#test").click( obj.test );
		</script>
	</body>

</html>